<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
</head>
<style>
.mui-btn {
	margin: 5px;
}
</style>
<body>
	<form class="mui-input-group mui-collapse-content">
		<input type="hidden" id="compId" value="${compId}">
		<div class="mui-input-row selectComp">
			<label>公司:</label> <select name="interest">
				<option value="">全部</option>
				<c:forEach items="${comps }" var="list">
					<option value="${list.compId }">${list.compName }</option>
				</c:forEach>
			</select>
		</div>
		<div class="mui-input-row like">
			<label>搜索：</label> <input type="text" id="like" name="like"
				placeholder="请输入位置或描述">
		</div>
		<div class="mui-button-row">
			<a class="mui-btn mui-btn-primary submit">提交</a>
		</div>
	</form>
	<div id="leg_table"></div>
	<script type="text/html" id="Bar">
		<a class="mui-btn mui-btn-primary edit">编辑</a>
		<a class="mui-btn mui-btn-primary del">删除</a>
	</script>
	<script type="text/javascript">
    	mui('#offCanvasContentScroll').scroll().scrollTo(0,0);
    
    	$(".mui-title").html("广告列表");
    	
		//公司
		$('.selectComp').on('change',function(){
		    //判断是否选取prompt属性，无返回值；
	        var compId = $(this).find('option:selected').val();
	        stateList = $.legTable({
	        	where:{
	        		compIdParam:compId
        		}
        	})
		});
		

	    $(".submit").on("touchstart",function(){
	    	var like = "%25"+$(".like input").val()+"%25";
	    	stateList = $.legTable({
	        	where:{
	        		like:like
        		}
        	});
	    })
		
		//接收数据
		var stateList = $.legTable({
			limit: 10,			//默认10
			page:1,				//默认1
			id:"#leg_table",	//绑定id
			url:"/publish/list",
			cols:[
				{field: 'caseNo', title: '储物柜的ID'},
	            {field: 'adName', title: '广告名称'},
	            {field: 'compName', title: '所属公司'},
	            {field: 'creatTime', title: '创建时间'},
	            {field: 'des', title: '描述'},
	            {field: 'place', title: '位置'},
	            {title: '操作',templet:'#Bar'}
	        ]
		});
		
		//添加
		$("#Add").show();
		$("#Add").on("touchstart",function(e){
			$("#Add").hide();
			url = "/publish/add";
			window.location.hash = url;
			sessionStorage.setItem("url",url)
		})
		
		//编辑
		$("#leg_table").on("touchstart", ".table-list .edit", function(e){
			let i = $(this).parent('data').attr("value");
			let url = "/publish/edit?fileId="+$.data(i).fileId;
			sessionStorage.setItem("url",url)
			window.location.hash = url;
			sessionStorage.setItem('publish', JSON.stringify($.data(i)));
	    });
		
		 //删除
         $("#leg_table").on("touchstart", ".table-list .del", function(e){
       	    let i = $(this).parent('data').attr("value");
   	    	mui.confirm('确定删除此广告？','温馨提示',function(e) {
			if (e.index == 1) {
				$.get("/publish/deleteAdvertise?id="+$.data(i).id,function(res){
	           		if (!res.success) {
	           			mui.toast(res.message);
	       			}else{
	       				mui.toast("删除成功");
	       				stateList = $.legTable();
	       			}
	           	})
			}
			})
        })

	</script>
</body>
</html>